<template>
  <div>
    <div>
      <input type="number" v-model="n1" />
    </div>
    <div>
      <input type="number" v-model="n2" />
    </div>
    {{ day }}
  </div>
  <div class="box">{{ 1 + 1 }}</div>
  <button @click="add">添加</button>
</template>
<script>
import moment from 'moment'
import { ref } from 'vue'
import { storeToRefs } from 'pinia'
import { dataURLtoBlob, dataURLtoFile } from '../../libs/dataURL.js'
import store from '@/store/index.js'
export default {
  data() {
    let { price, priceEnd } = storeToRefs(store)
    return {
      n2: priceEnd,
      n1: price
    }
  },
  computed: {
    day() {
      return this.sleepDay()
    }
  },
  methods: {
    sleepDay() {
      let num = this.n2 / this.n1
      let day = Math.log(num) / Math.log(1.1)
      console.log(day)
      day = Math.floor(day)
      //去除周六日
      if (day > 0 && day < 1000) {
        let now = moment()
        while (day) {
          now = now.add(1, 'd')
          if ([0, 6].includes(now.day())) {
            continue
          } else {
            day--
          }
        }
        return now.format('YYYY-MM-DD')
      }
      //return day;
    },
    add() {
      console.log(`helloworld`)
      this.sleepDay()
    }
  },
  mounted() {
    console.log(`helloworld`)

    console.log(`helloworld`)
    const myBlob = new Blob(['Hello, world!'], { type: 'text/plain' })

    // 创建一个FileReader实例
    const reader = new FileReader()

    // 设置FileReader的onload事件处理程序，当读取操作完成时会被调用
    reader.onload = function(event) {
      // 读取操作完成，event.target.result包含了读取的结果
      const contents = event.target.result
      console.log(contents) // 输出Blob的内容

      let res = dataURLtoBlob(contents)
      let file = dataURLtoFile(contents)
      console.log(res, file)
    }

    // 使用FileReader的readAsText方法读取Blob
    // 这会异步开始读取操作，并在完成后触发onload事件
    //reader.readAsText(myBlob);
    reader.readAsDataURL(myBlob)

    let arr = [1, 2, 3, 4, 5]
    let n = arr.length
    let newArray = new Array(n)
    //可以少一个变量定义
    while (n--) {
      newArray[n] = arr[n]
    }
    console.log(newArray)

    let m1 = moment('2024-10-14')
    let m2 = moment('2024-10-14')
    let m3 = moment('2024-10-15')
    let flag = m1.isSameOrAfter(m2) && m1.isSameOrBefore(m3)
    //其实开头判断就行了，结尾不用判断除非数据错误了
    console.log(flag)
  }
}
</script>
<style type="text/css">
.box {
  width: 100px;
  height: 100px;
  border: 1px solid #000;
}
</style>
